<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/config.inc.php');
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/top.inc.php');

$subject_id = mysql_real_escape_string(strip_tags($_GET['sid']));

$get_subject_data = mysql_query("SELECT * FROM course_subjects WHERE id = $subject_id");
$subject_name = mysql_result($get_subject_data,0,'subject_title');
$abbreviation = mysql_result($get_subject_data,0,'abbreviation');

echo "<p>";
	echo "<a href='courses.php?id=$subject_id'>&lt;&lt; Back to Courses Portal</a><br />";
echo "</p>";
echo "<h1>Add Course for $subject_name</h1>";

$query="SELECT * FROM courses WHERE course_subject_id=$subject_id";
$result=mysql_query($query);

//determine dynamically number of rows read from table
$num_rows=mysql_numrows($result);

$i=0;


echo "<form action='add_do.php' method='post'>";

//start table
echo "<table border='0'>";
	
	//create table row
	echo "<tr>";
		echo "<td width=180><b>Course Number: </b></td>";
		echo "<td>$abbreviation <input type='text' name='course_num'></td>";
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Course Name: </b></td>";
		echo "<td><input type='text' name='course_name'></td>";
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Credits: </b></td>";
		echo "<td><input type='text' name='credits'></td>";
	echo "</tr>";
	
	//create table row
	echo "<tr>";
		echo "<td><b>Graduate Course: </b></td>";
		echo '<td>';
			echo "<select name='grad'>";
				echo "<option value=1>Yes</option>";
				echo "<option value=0>No</option>";
			echo "</select>";
		echo '</td>';
	echo "</tr>";
	
	echo "<tr>";
		echo "<td><b>Lab:</b></td>";
		echo "<td>";
			echo "<select name='lab'>";
				echo "<option value=0>NONE</option>";
				while ($i < $num_rows)
				{
					$lab_id=mysql_result($result,$i,"id");
					$lab_number=mysql_result($result,$i,"course_number");
					echo "<option value=$lab_id>$abbreviation $lab_number</option>";
					$i++;
				}
			echo "</select>";
		echo '</td>';
	echo "</tr>";


//end table tag
echo "</table>";

echo "<input type='hidden' name='sid' value='$subject_id'>";
echo "<p><input type='submit'></p>";
echo '</form>';


?>

<?php
	require_once($_SERVER['DOCUMENT_ROOT'].'uno-course-scheduler/include/bottom.inc.php');
?>